<template>
  <div class="tab-control">
    <div class="tab-control-item" :class="{active:index == currentIndex}" v-for="(item, index) in titles" :key="index" @click="itemClick(index)">
      <span>{{item}}</span>
    </div>
  </div>
</template>

<script>
import {ref} from "vue"
export default {
  name: "TabControl",
  setup(props, {emit}) {
    let currentIndex = ref(0);

    const itemClick = (index) => {
      currentIndex.value = index;
      emit("tabClick", index)
    }
    return {
      currentIndex,
      itemClick
    }
  },
  props: {
    titles: {
      type: Array,
      default() {
        return [];
      },
    },
  },
};
</script>

<style scoped lang="scss">
.tab-control {
  display: flex;
  height: 40px;
  line-height: 40px;
  font-size: 15px;
  text-align: center;
  background-color: #eee;
  width: 100%;
  position: sticky;
  top: 45px;
  z-index: 10;
  .tab-control-item {
    flex: 1;
    span {
      padding: 4px;
    }
  }

  .active {
    color: var(--color-tint);
    background-color: var(--color-background);
    span {
      border-bottom: 2px solid var(--color-tint);
    }
  }
}
</style>
